/**
 * Created by dqw on 2015/12/30.
 */
//列表开始
var dtGridColumns = [
    {
        id: 'delFlag',
        type: 'int',
        hideQuery:true,
        'export':false,
        hideQueryType:'eq',
        hideQueryValue:1,
        hide:true
    },
    {
        id: 'userId',
        type: 'number',
        hideQuery:true,
        'export':false,
        hide:true
    },
    {
        id: 'id',
        title: 'ID',
        type: 'int',
        columnClass: 'text-center width-100',
        fastSort: true,
        fastQuery: false
    },
    {
        id: 'u.userName',
        title: '用户姓名',
        type: 'string',
        headerClass: 'text-left',
        columnClass: 'text-left width-200',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'u.mobilePhone',
        title: '用户手机',
        type: 'string',
        headerClass: 'text-left',
        columnClass: 'text-left width-200',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'direction',
        title: '收支',
        type: 'string',
        headerClass: 'text-left',
        columnClass: 'text-left',
        fastSort: false,
        fastQuery: false,
        codeTable:{
          1:$lang.direction.payment,
          2:$lang.direction.receive
        },
    },
    {
        id: 'amount',
        title: '操作金额',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-right',
        fastSort: false,
        fastQuery: false,
        format:'#,##0.00',
        fastQueryType: 'lk'
    },
    {
        id: 'total',
        title: '剩余金额',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-right width-200',
        fastSort: false,
        fastQuery: false,
        format:'#,##0.00',
        fastQueryType: 'lk'
    },
    {
        id: 'type',
        title: '资金变动类型',
        type: 'string',
        headerClass: 'text-left',
        columnClass: 'text-left',
        fastSort: false,
        fastQuery: false,
        fastQueryType: 'lk',
        codeTable:{
            1:$lang.accountLogType.T1,
            2:$lang.accountLogType.T2,
            3:$lang.accountLogType.T3,
            4:$lang.accountLogType.T4,
            5:$lang.accountLogType.T5,
            6:$lang.accountLogType.T6,
            7:$lang.accountLogType.T7,
            8:$lang.accountLogType.T8,
            9:$lang.accountLogType.T9,
            10:$lang.accountLogType.T10,
            11:$lang.accountLogType.T11,
            12:$lang.accountLogType.T12,
            13:$lang.accountLogType.T13,
            14:$lang.accountLogType.T14,
            15:$lang.accountLogType.T15,
            16:$lang.accountLogType.T16,
            17:$lang.accountLogType.T17,
            18:$lang.accountLogType.T18,
            19:$lang.accountLogType.T19,
            20:$lang.accountLogType.T20,
            21:$lang.accountLogType.T21,
            22:$lang.accountLogType.T22,
            23:$lang.accountLogType.T23,
            24:$lang.accountLogType.T24,
            25:$lang.accountLogType.T25,
        },
    },
    {
        id: 'createTime',
        title: '修改时间',
        type: 'date',
        format:'yyyy-MM-dd',
        headerClass: 'text-left',
        columnClass: 'text-left',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'range'
    },
];

var dtGridOption = {
    lang: 'zh-cn',
    ajaxLoad: true,
    loadURL: ncGlobal.adminRoot + 'accountLog/list.json',
    exportURL:ncGlobal.adminRoot + 'accountLog/export.json',
    exportFileName: '资金记录列表',
    columns: dtGridColumns,
    gridContainer: 'dtGridContainer',
    toolbarContainer: 'dtGridToolBarContainer',
    pageSize: 10,
    pageSizeLimit: [10, 20, 50],
    ncColumnsType: {int:["id","type","userId"],Timestamp:["createTime"],decimal:["amount","total"]},
    tools:'refresh|faseQuery|export[excel]',
};

var grid = $.fn.DtGrid.init(dtGridOption);
grid.fastQueryParameters = new Object();
grid.fastQueryParameters['eq_delFlag'] = 1;

//排序
grid.sortParameter.columnId = ['desc_id','desc_createTime'];
grid.sortParameter.sortType = 1;
//列表结束

//操作处理开始
var OperateHandle = function () {

    function _bindEvent() {

        //新增对话框初始化
        $("#addModal").on("show.bs.modal", function (event) {
            //清除错误信息
            $(".alert-danger").remove();
            $("#addForm").psly().reset();

            $.each($("#addForm input"),function (i, v) {
                $(v).val('');
            })
        });

        //编辑对话框初始化
        $("#editModal").on("show.bs.modal", function (event) {
            //清除错误信息
            $(".alert-danger").remove();
            $("#editForm").psly().reset();
            //获取接受事件的元素
            var button = $(event.relatedTarget);
            //获取data 参数
            var datano = button.data('no');
            var modal = $(this);
            //获取列表框中的原始数据
            var gridData = grid.sortOriginalDatas[datano];
            investAccount = gridData.investAccount;

            $("#investId").val(gridData.id);
            $("#adminName").val(gridData.name);
            modal.find("[name='password']").val("");
            modal.find("[name='password2']").val("");
            modal.find("[name='roleId']").val(gridData.roleId);
        });

        //模糊搜索
        $('#customSearch').click(function () {
            grid.fastQueryParameters = new Object();
            grid.fastQueryParameters['eq_delFlag'] = 1;
            grid.fastQueryParameters['lk_u.user_name_or_like_u.mobile_phone'] = $('#keyword').val();
            grid.pager.startRecord = 0;
            grid.pager.nowPage = 1;
            grid.pager.recordCount = -1;
            grid.pager.pageCount = -1;
            grid.refresh(true);
        });
    }

    //外部可调用
    return {
        bindEvent: _bindEvent
    }
}();
//操作处理结束

$(function () {
    //加载列表
    grid.load();
    //页面绑定事件
    OperateHandle.bindEvent();
});